package DAO.impl;

import javax.persistence.Query;

import DAO.HibernateUtil;
import DAO.StationDAO;

import model.impl.Station;

public class StationDAOImpl extends GenericDAOImpl<Station, Integer> implements
		StationDAO {

	public Station findStationByName(String name) {
		Station station = null;
		try {
			HibernateUtil.beginTransaction();
			String sqlRequest = "SELECT s FROM Station s WHERE s.stationName = :name";
			Query query = HibernateUtil.getSession().createQuery(sqlRequest).setParameter("name", name);
			station = findOne(query);
			HibernateUtil.commitTransaction();
		}  catch (Exception e) {
			HibernateUtil.rollbackTransaction();
			e.printStackTrace();
            System.out.println("Error in findStationByName");
        }
		return station;
	}

}
